package view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


/**
 * This class serves as a base for the 
 * community and chance cards.
 * It provides an image as well as a label
 * for the the text to be displayed.
 * 
 * @author Thomas
 *
 */
abstract class CustomDialog extends JDialog implements ActionListener
{
	protected ImageIcon image = ImageCreator.createImageIcon("Images/figur_test.png");
	
	public CustomDialog(String title, String text) 
	{
		super();
		this.setTitle(title);
		
		JLabel imageLabel = new JLabel(image);
		JPanel messagePanel = new JPanel();
		JPanel buttonPanel = new JPanel();
		JPanel imagePanel = new JPanel();
		
		JTextArea messageArea = new JTextArea(5, 15);
		messageArea.setLineWrap(true);
		messageArea.setWrapStyleWord(true);
		messageArea.setText(text);
		messageArea.setEditable(false);
		messageArea.setBackground(null);
		messageArea.setFont(new Font("Times New Roman", Font.PLAIN, 20));
		
		imagePanel.add(imageLabel);
		
		messagePanel.add(messageArea);
		//messagePanel.setPreferredSize(new Dimension(300, 80));
		
		JButton ok  = new JButton("OK");
		ok.setActionCommand("ok");
		ok.addActionListener(this);
		buttonPanel.add(ok);
		this.getRootPane().setDefaultButton(ok);
		this.getRootPane().setLayout(new BorderLayout());
		this.getRootPane().add(messagePanel, BorderLayout.EAST);
		this.getRootPane().add(buttonPanel, BorderLayout.SOUTH);
		this.getRootPane().add(imagePanel, BorderLayout.WEST);
		
		this.setModal(true);
		this.pack();
		this.setLocation(280, 230);
		this.setVisible(true);
	}
	
	/**
	 * ActionListener 
	 */
	public void actionPerformed(ActionEvent event)
	{
		if(event.getActionCommand().equalsIgnoreCase("ok"))
			this.dispose();
	}
}
